<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>鼠标事件</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        list-style-type: none;
      }

      ul {
        height: 100vh;
        display: flex;
        flex-direction: column;

        li {
          flex: 1;
          border-bottom: 1px solid #000;
        }
      }
    </style>
  </head>
  <body>
    <ul>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>
    <script>
      liEles = document.querySelectorAll('ul li')

      for (i = 0; i < liEles.length; i++) {
        liEles[i].addEventListener('mouseover', function () {
          this.style.backgroundColor = 'skyblue'
        })
        liEles[i].addEventListener('mouseout', function () {
          this.style.backgroundColor = ''
        })
        liEles[i].addEventListener('mousedown', function () {
          this.style.backgroundColor = 'black'
          console.log('鼠标按下了')
        })
        liEles[i].addEventListener('mouseup', function () {
          this.style.backgroundColor = 'skyblue'
          console.log('鼠标松开了')
        })
      }
    </script>
  </body>
</html>
